<% apps_menu = Application.get_env(:block_scout_web, :apps_menu) %>
<% other_nets = dropdown_other_nets() %>
<% test_nets = test_nets(dropdown_nets()) %>
<% main_nets = dropdown_head_main_nets() %>
<nav class="navbar navbar-dark navbar-expand-lg navbar-primary" data-selector="navbar" id="top-navbar">
  <div class="container-fluid navbar-container">
    <%= link to: webapp_url(@conn), class: "navbar-brand", "data-test": "header_logo" do %>
      <%= if logo() do %>
        <img class="navbar-logo" id="navbar-logo" src="<%= static_path(@conn, logo()) %>" alt="<%= subnetwork_title() %>" />
      <% end %>
      <%= if logo_text() do %>
        <span class="logo-text <%= unless logo(), do: "no-logo" %>"> <%= logo_text() %> </span>
      <% end %>
      <%= if Application.get_env(:block_scout_web, BlockScoutWeb.Chain)[:enable_testnet_label] do %>
        <%= render BlockScoutWeb.FormView, "_tag.html", text: "", additional_classes: ["testnet-label", "ml-2"] %>
      <% end %>
    <% end %>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="<%= gettext("Toggle navigation") %>">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav">
        <%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %>
          <li class="nav-item dropdown">
            <a class="nav-link topnav-nav-link dropdown-toggle" href="#" id="navbarBlocksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              <span class="nav-link-icon">
                <%= render BlockScoutWeb.IconsView, "_blockchain_icon.html" %>
              </span>
              <%= gettext("Blockchain") %>
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarBlockchainDropdown">
              <div class="nav-submenu">
                <span>
                  <%= gettext("Blocks") %>
                </span>
              </div>
              <%= link(
                    gettext("Blocks"),
                    to: blocks_path(@conn, :index),
                    class: "dropdown-item #{tab_status("blocks", @conn.request_path)}")%>
              <%= link(gettext("Uncles"),
                    to: uncle_path(@conn, :uncle),
                    class: "dropdown-item #{tab_status("uncles", @conn.request_path)}")%>
              <%= link(gettext("Forked Blocks (Reorgs)"),
                    to: reorg_path(@conn, :reorg),
                    class: "border-bottom dropdown-item #{tab_status("reorgs", @conn.request_path)}")%>
              <div class="nav-submenu">
                <span>
                  <%= gettext("Transactions") %>
                </span>
              </div>
              <% json_rpc_named_arguments = Application.fetch_env!(:indexer, :json_rpc_named_arguments) %>
              <% variant = Keyword.fetch!(json_rpc_named_arguments, :variant) %>
              <% show_withdrawals? = not Application.get_env(:indexer, Indexer.Fetcher.Withdrawal.Supervisor)[:disabled?] %>
              <%= link(
                    gettext("Validated"),
                    to: transaction_path(@conn, :index),
                    class: "#{if variant == EthereumJSONRPC.Besu, do: "border-bottom", else: ""} dropdown-item #{tab_status("txs", @conn.request_path)}"
                  ) %>

              <%= if variant !== EthereumJSONRPC.Besu do %>
                <%= link(
                      gettext("Pending"),
                      class: "border-bottom dropdown-item #{tab_status("pending-transactions", @conn.request_path)}",
                      "data-test": "pending_transactions_link",
                      to: pending_transaction_path(@conn, :index)
                    ) %>
              <% end %>
              <%= link(gettext("Verified contracts"),
                    to: verified_contracts_path(@conn, :index),
                    class: "dropdown-item border-bottom #{tab_status("reorgs", @conn.request_path)}")%>
              <%= if show_withdrawals? do %>
                <%= link(gettext("Withdrawals"),
                    to: withdrawal_path(@conn, :index),
                    class: "dropdown-item #{tab_status("reorgs", @conn.request_path)}")%>
              <% end %>
            </div>
          </li>
          <li class="nav-item dropdown">
            <a href="#" role="button" id="navbarTokensDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              <span class="nav-link-icon">
                <%= render BlockScoutWeb.IconsView, "_tokens_icon.html" %>
              </span>
              <%= gettext("Tokens") %>
            </a>
            <div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown"> 
              <%= link(
                    gettext("All"),
                    class: "dropdown-item #{tab_status("tokens", @conn.request_path)}",
                    to: tokens_path(@conn, :index)
                  ) %>
              <%= link(
                    Explorer.coin_name(),
                    class: "dropdown-item #{tab_status("accounts", @conn.request_path)}",
                    to: address_path(@conn, :index)
                  ) %>
            </div>
          </li>
        <% end %>
        <%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:reading_enabled] || Application.get_env(:block_scout_web, :api_url) do %>
          <li class="nav-item dropdown">
            <a href="#" role="button" id="navbarAPIsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              <span class="nav-link-icon">
                <%= render BlockScoutWeb.IconsView, "_api_icon.html" %>
              </span>
              <%= gettext("APIs") %>
            </a>
            <div class="dropdown-menu" aria-labeledby="navbarTransactionsDropdown"> 
              <%= link(
                    gettext("GraphQL"),
                    class: "dropdown-item #{tab_status("graphiql", @conn.request_path)}",
                    to: api_url() <> "/graphiql"
                  ) %>
              <%= link(
                    gettext("RPC"),
                    class: "dropdown-item #{tab_status("api-docs", @conn.request_path)}",
                    to: api_url() <> api_docs_path(@conn, :index)
                  ) %>
              <%= link(
                    gettext("Eth RPC"),
                    class: "dropdown-item #{tab_status("eth-rpc-api-docs", @conn.request_path)}",
                    to: api_url() <> api_docs_path(@conn, :eth_rpc)
                  ) %>
            </div>
          </li>
        <% end %>
        <%= if apps_menu == true do %>
          <li class="nav-item dropdown">
            <a href="#" role="button" id="navbarAppsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              <span class="nav-link-icon">
                <%= render BlockScoutWeb.IconsView, "_apps_icon.html" %>
              </span>
              <%= if apps_menu == true do %>
                <%= gettext("Apps") %>
              <% else %>
                <%= gettext("Stakes") %>
              <% end %>
            </a>
            <div class="dropdown-menu" aria-labeledby="navbarAppsDropdown">
              <%= if apps_menu == true do %>
                <%= for %{url: url, title: title} = app <- apps_list() do %>
                    <%= if Map.has_key?(app, :embedded?) && app.embedded? do %>
                      <a href="<%= url %>" class="dropdown-item" target="_self"><%= title %></a>
                    <% else %>
                      <a href="<%= url %>" class="dropdown-item" target="_blank"><%= title %>
                        <span class="external-link-icon">
                          <%= render BlockScoutWeb.IconsView, "_external_link.html" %>
                        </span>
                      </a>
                    <% end %>
                <% end %>
              <% end %>
            </div>
          </li>
        <% end %>
        <li class="nav-item dropdown">
          <a class="nav-link topnav-nav-link active-icon <%= if dropdown_nets() != [], do: "dropdown-toggle" %>" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="nav-link-icon">
              <%= render BlockScoutWeb.IconsView, "_active_icon.html" %>
            </span>
            <%= subnetwork_title() %>
          </a>
          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> 
            <%= if Enum.count(main_nets) > 0 do %>
              <a class="dropdown-item header division">Mainnets</a> 
              <%= for %{url: url, title: title} <- main_nets do %>  
                <a class="dropdown-item" href="<%= url %>"><%= title %></a>
              <% end %>
            <% end %>
            <%= if Enum.count(test_nets) > 0 do %>
              <a class="dropdown-item header division">Testnets</a> 
              <%= for %{url: url, title: title} <- test_nets do %> 
                <a class="dropdown-item" href="<%= url %>"><%= title %></a>
              <% end %>
            <% end %>
            <%= if Enum.count(other_nets) > 0 do %>
              <a class="dropdown-item header division">Other Networks</a> 
              <%= for %{url: url, title: title} <- other_nets do %>  
                <a class="dropdown-item" href="<%= url %>"><%= title %></a>
              <% end %> 
            <% end %>
          </div>
        </li>
        <!-- Dark mode changer -->
        <%= unless Application.get_env(:block_scout_web, :permanent_light_mode_enabled) || Application.get_env(:block_scout_web, :permanent_dark_mode_enabled) do %>
          <button class="dark-mode-changer" id="dark-mode-changer">
            <svg xmlns="http://www.w3.org/2000/svg" width="15" height="16">
              <path fill="#9B62FF" fill-rule="evenodd" d="M14.88 11.578a.544.544 0 0 0-.599-.166 5.7 5.7 0 0 1-1.924.321c-3.259 0-5.91-2.632-5.91-5.866 0-1.947.968-3.759 2.59-4.849a.534.534 0 0 0-.225-.97A5.289 5.289 0 0 0 8.059 0C3.615 0 0 3.588 0 8s3.615 8 8.059 8c2.82 0 5.386-1.423 6.862-3.806a.533.533 0 0 0-.041-.616z"/>
            </svg>
          </button>
        <% end %>
        <%= render BlockScoutWeb.LayoutView, "_account_menu_item.html", conn: @conn, current_user: @current_user %>
      </ul>
      <%= render BlockScoutWeb.LayoutView, "_search.html", conn: @conn, id: "main-search-autocomplete", additional_classes: ["mobile-search-hide"] %>
    </div>
  </div>
  <%= render BlockScoutWeb.LayoutView, "_search.html", conn: @conn, id: "main-search-autocomplete-mobile", additional_classes: ["mobile-search-show"] %>
</nav>
